package com.dongdongshop.service.impl;

import com.dongdongshop.domain.model.TbAreas;
import com.dongdongshop.domain.model.TbAreasExample;
import com.dongdongshop.domain.vo.AreasVO;
import com.dongdongshop.mapper.TbAreasMapper;
import com.dongdongshop.service.AreasService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class AreasServiceImpl implements AreasService {

    @Autowired
    private TbAreasMapper areasMapper;

    @Override
    public List<AreasVO> getAreasByCityId(String cityId) {
        TbAreasExample areasExample = new TbAreasExample();
        areasExample.createCriteria().andCityidEqualTo(cityId);
        List<TbAreas> tbAreas = areasMapper.selectByExample(areasExample);
        return tbAreas.stream().map(areas -> {
            AreasVO vo = new AreasVO();
            BeanUtils.copyProperties(areas,vo);
            return vo;
        }).collect(Collectors.toList());
    }
}
